<title>后台管理员</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>用户</cite></a>
        <a><cite>后台管理员</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>
            </div>

            <table id="LAY-home-admin-list" lay-filter="LAY-home-admin-list"></table>
            <script type="text/html" id="LAY-home-admin-tools">
                {{# if(d.user_id != JSON.parse(layui.data(layui.setter.tableName).user_info).user_id || d.agency_id == 0) { }}
                <!--                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="resetPwd"><i-->
                <!--                        class="layui-icon layui-icon-edit"></i>重置密码</a>-->
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
                {{# } }}
            </script>
        </div>
    </div>

</div>

<script>
    layui.use('useradmin', layui.factory('useradmin')).use(['admin', 'useradmin', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form;

        var tableElem = "LAY-home-admin-list";
        var adminFormElem = "LAY-home-admin-adminform-form";
        var adminFormSubmitElem = "LAY-home-admin-adminform-form-submit";

        //事件
        var active = {
            add: function () {
                admin.popup({
                    title: '添加管理员'
                    , area: ['420px', '450px']
                    , id: 'LAY-popup-useradmin-add'
                    , success: function (layero, index) {
                        view(this.id).render('user/administrators/adminform').done(function () {
                            form.render(null, adminFormElem);

                            //提交
                            form.on(`submit(${adminFormSubmitElem})`, function (data) {
                                var field = data.field; //获取提交的字段
                                field.email = field.user_name

                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                admin.req({
                                    url: window.globalConfig.url_user,
                                    type: "POST",
                                    data: field,
                                    success: function (res) {
                                        layui.table.reload(tableElem); //重载表格
                                        layer.close(index); //执行关闭
                                    }
                                })
                            });
                        });
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>